package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.constant.RedisConstant;
import com.itheima.entity.Result;
import com.itheima.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;

/**
 * @author 吴
 * @version V1.0
 * @Description
 * @Package com.itheima.controller
 * @date 2021/12/9 19:14
 */
@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private JedisPool jedisPool;

    @Reference
    private PayService payService;

    @GetMapping("/findIsPay/{orderNumber}")
    public Result findIsPay(@PathVariable("orderNumber") String orderNumber){
        try {
            String number = payService.findByOrderNumber(orderNumber);
            if("支付成功".equals(number)){
                return new Result(true, MessageConstant.PAY_SUCCESS);
            }
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.PAY_FAIL);
        }
        return new Result(false, MessageConstant.PAY_FAIL);
    }
}
